package com.wsj.neo4j.simple.config;

import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Spring Data Neo4j repositories using JavaConfig
 *
 * @author WangSongJun
 * @date 2019-10-24
 */
@Configuration
@EnableNeo4jRepositories(
        basePackages = "com.wsj.neo4j.simple.repository",
        sessionFactoryRef = "primarySessionFactory",
        transactionManagerRef = "primaryNeo4jTransactionManager"
)
@EnableTransactionManagement
public class PrimaryConfiguration {

    @Autowired
    @Qualifier("primarySessionFactory")
    private SessionFactory sessionFactory;


    @Primary
    @Bean("primaryNeo4jTransactionManager")
    public Neo4jTransactionManager transactionManager() {
        return new Neo4jTransactionManager(sessionFactory);
    }

}
